<?php
/**
 * 个人会员中心 基础类
 * @author      HJC <hujianchuang@haowj.com>
 * @update      2014.06.23
 * @since       Version 1.0
 * 
 */
class BaseAction extends  Action
{
    var $userInfo = '';
    public function __construct()
    {
        parent::__construct();
        $nowurl =  urlencode(get_url());
        //判断登录状态
        if(!cookie('haowj_ustat'))  redirect(C('WWWURL').'/userlogin/index.htm?fromurl='.$nowurl);
        $haowj_ustat = json_decode(MAGIC_QUOTES_GPC?stripslashes(cookie('haowj_ustat')):cookie('haowj_ustat'),true);
        
        if(cookie('adminToUser')&&cookie('adminMobile'))
        {
            $haowj_ustat['i'] = $_COOKIE['adminMobile'];
        }
        $this->userInfo = D('User')->checkLogin($haowj_ustat);
        if(!$this->userInfo) $this->error('ERROR DATA!');
        $this->assign('userInfo',$this->userInfo);
        $this->assign('module_name',MODULE_NAME);
        $this->assign('group_name',GROUP_NAME);
        //判断是否已经够买了
        $packOrder = D('Order')->where("flag=10 and status=1 and user_id= ".$this->userInfo['id'])->getField('id');
        if(!$packOrder) redirect(C('WWWURL').'/usercenter/index.htm');
        
        //判断有没有其他订单
        $ortherOrder = D('Order')->where("flag>0 and flag!=10 and status=1 and user_id= ".$this->userInfo['id'])->getField('id');
        $this->assign('ortherOrder',$ortherOrder);
        //评分剩余
        $pjNum = D('Grade')->where("user_id=".$this->userInfo['id']." and type=10 and flag=0 ")->count("id");
        $this->assign('plnum',$pjNum);
        //赋值三要素
        $this->assSeo();
        $this->assign('packenterclassroomtime',C('PACKENTERCLASSROOMTIME'));
    }
    //空操作
    public function _empty()
    {
        die('错误了哦！');
    }
    
    
    //title 三要素处理
    public  function assSeo($title='',$keywords='',$description='')
    {
        if($title=='') $title = C('SEOTITLE'); 
        if($keywords=='') $keywords = C('SEOKEYWORDS'); 
        if($description=='') $description = C('SEODESCRIPTION'); 
        $seo['title']       = $title;
        $seo['keywords']    = $keywords;
        $seo['description'] = $description;
        $this->assign('seo',$seo);
    }
    //退出登录
    public function loginExit()
    {
        $_SESSION["_user_login_haowaijiao"] = "";
        setcookie('haowj_ustat',"",time() - 86400,'/','.haowj.com');
        $this->ajaxReturn('','成功！',1);
    }
}